home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group99a.txt / 000160_icon-group-sender _Mon Jul 19 08:29:31 1999.msg < prev    next >
Internet Message Format  |  2000-09-20  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id IAA05286
  4.     for icon-group-addresses; Mon, 19 Jul 1999 08:29:23 -0700 (MST)
  5. Message-Id: <199907191529.IAA05286@baskerville.CS.Arizona.EDU>
  6. From: "Frank Lhota" <lhotaf@lexma.meitech.com>
  7. To: <icon-group@optima.CS.Arizona.EDU>, "Garry" <memphis@macconnect.com>
  8. Subject: Re: [Q][newbie] Why use a useless loop?
  9. Date: Mon, 19 Jul 1999 11:22:52 -0400
  10. X-Priority: 3
  11. X-MSMail-Priority: Normal
  12. X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
  13. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  14. Status: RO
  15.  
  16. You're right. the loop appears to be unnecessary. My guess is that it is a
  17. fossil remain of a previous implementation.
  18.  
  19. One thing that strikes me about the implementation of both this procedure
  20. and of basename is the use of a variable to store a position in the subject
  21. string. Frankly, I do not know why this is done when a simpler and more
  22. straightforward solution can be obtained by using the tab function. for
  23. example, we can implement lastname as follows:
  24.  
  25.    procedure lastname(s)
  26.       local line
  27.  
  28.       line := trim(s)
  29.       line ?:= tab(find(",")) # Get rid of things like " ... , Jr."
  30.       line ? {
  31.           while tab(find(" ")+1) # Move past all blanks.
  32.           return tab(0)
  33.           }
  34.    end
  35.  
  36. Now isn't that clearer than the version that uses the local variable i to
  37. store positions?
  38.  
  39. ----- Original Message -----
  40. From: Garry <memphis@macconnect.com>
  41. To: <icon-group@optima.CS.Arizona.EDU>
  42. Sent: Thursday, July 15, 1999 10:08 PM
  43. Subject: [Q][newbie] Why use a useless loop?
  44.  
  45.  
  46. > There is a wonderful little procedure, lastname(s), in the Icon Library
  47. > for extracting the last name from a string s representing a person's
  48. > full name. (It seems wonderful to me considering how compact yet
  49. > tolerant it is, and how I would write it in other languages <ugh>).
  50. >
  51. > e.g. lastname("Dr. I. M. Zany, Jr.") produces a "Zany" result.
  52. >
  53. > The implementation is
  54. > #       File:     lastname.icn
  55. > #       Subject:  Procedure to produce last name
  56. > #       Author:   Ralph E. Griswold
  57. > #       Date:     April 30, 1993
  58. > #
  59. > #  Produces the last name of a name in conventional form.  Obviously, it
  60. > #  doesn't work for every possibility.
  61. >
  62. > procedure lastname(s)
  63. >    local line, i
  64. >
  65. >    while line := trim(s) do {
  66. >       line ?:= tab(upto(',')) # Get rid of things like " ... , Jr."
  67. >       line ? {
  68. >           every i := upto(' ')
  69. >           tab(\i + 1)
  70. >           return tab(0)
  71. >           }
  72. >       }
  73. > end
  74. >
  75. >
  76. > My problem is that I can't think of any reason for writing
  77. >   while line := trim(s) do { ... }
  78. > instead of just
  79. >    line := trim(s)
  80. >
  81. > Can anyone see a need for the "while"?  If so, please teach me. I did of
  82. > course already spend more than one full minute thinking about this and
  83. > looked up trim() in the Icon book. Maybe there really is no need for the
  84. > "while" but then I've observed that I'm blind to my blind spots.
  85. >
  86. > --
  87. > Garry
  88. > Tech Writer & Freelance Programmer
  89. >
  90.  
  91.